// Created from GroupGenerationTemplate
// For Decisions HL7 Engine
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Runtime.Serialization;
using DecisionsFramework.Design.Properties;
using Decisions.HL7.DataTypes;
using ST = System.String;
using SI = System.String;
using IS = System.String;
using ID = System.String;
using SNM = System.String;

namespace Decisions.HL7.Message
{
    [DataContract]
	public class GOAL_CQU_I19 : AbstractGroup
    {
        /// -----------------------------
        /// -----------------------------
		[DataMember]
	    [PropertyClassification("126 GOL",126)]
  	    [HL7Field(HL7Version.v27, 126, HL7Repeat.False, HL7Required.True,"GOL")]
	    public GOL GOL {get;set;}

        /// -----------------------------
        /// -----------------------------
		[DataMember]
	    [PropertyClassification("127 VAR",127)]
  	    [HL7Field(HL7Version.v27, 127, HL7Repeat.True, HL7Required.False,"VAR")]
	    public VAR[] VAR {get;set;}

        /// -----------------------------
        /// -----------------------------
		[DataMember]
	    [PropertyClassification("128 ROLE_GOAL",128)]
  	    [HL7Field(HL7Version.v27, 128, HL7Repeat.True, HL7Required.False,"ROLE_GOAL_CQU_I19")]
	    public ROLE_GOAL_CQU_I19[] ROLE_GOAL {get;set;}

        /// -----------------------------
        /// -----------------------------
		[DataMember]
	    [PropertyClassification("138 OBX",138)]
  	    [HL7Field(HL7Version.v27, 138, HL7Repeat.True, HL7Required.False,"OBX")]
	    public OBX[] OBX {get;set;}



		#region Parser Helpers and Conrete Impls

        internal override void ConsumeTextSegmentsForGroup(Stack<string> availableData, HL7ParserOptions options) {

			GOL = PopSegmentParseAndCheckRequired<GOL>(availableData, options, "GOL");
			VAR = PopSegmentParseAndCheckRequiredArray<VAR>(availableData, options, "VAR");
			ROLE_GOAL = ProcessGroupArray<ROLE_GOAL_CQU_I19>(availableData, options, "ROLE_GOAL");
			OBX = PopSegmentParseAndCheckRequiredArray<OBX>(availableData, options, "OBX");
        }

		internal override bool CanConsume(string availableData, HL7ParserOptions options)
        {
			bool isGOL = availableData.StartsWith("GOL", StringComparison.OrdinalIgnoreCase);
			if (IsRequired("GOL", options.Version) || isGOL) {
				return isGOL;
			}
			bool isVAR = availableData.StartsWith("VAR", StringComparison.OrdinalIgnoreCase);
			if (IsRequired("VAR", options.Version) || isVAR) {
				return isVAR;
			}
			ROLE_GOAL_CQU_I19 testROLE_GOAL_CQU_I19 = new ROLE_GOAL_CQU_I19();
			bool grpCCROLE_GOAL_CQU_I19 = (testROLE_GOAL_CQU_I19.CanConsume(availableData, options));
			if (IsRequired("ROLE_GOAL", options.Version) || grpCCROLE_GOAL_CQU_I19) {
				return grpCCROLE_GOAL_CQU_I19;
			}
			bool isOBX = availableData.StartsWith("OBX", StringComparison.OrdinalIgnoreCase);
			if (IsRequired("OBX", options.Version) || isOBX) {
				return isOBX;
			}
			return false;
        }

        private static Dictionary<string, bool> SEGMENT_VERSION_REQUIRED_MAP = new Dictionary<string, bool>();

		protected override Dictionary<string, bool> MAP_OF_SEGMENT_TO_REQUIRED
        {
            get
			{
				return SEGMENT_VERSION_REQUIRED_MAP;
			}
        }

		public override string HL7ENTITY_TYPE_NAME
        {
            get {
				return "GOAL";
			}
        }

        static GOAL_CQU_I19() {

             SetupStaticPropertyMap(SEGMENT_VERSION_REQUIRED_MAP, typeof(GOAL_CQU_I19));

        }

		#endregion

		public override string GetER7(HL7ParserOptions options)
		{
			List<string> segmentData = new List<string>();
		 if (GOL != null) {
			string segmentValue = GOL.GetER7(options);
			if (string.IsNullOrEmpty(segmentValue) == false) {
				segmentData.Add(segmentValue);
			}
		 }
		 if (VAR != null && VAR.Length > 0) {
			for (int i = 0; i < VAR.Length; i++) {
				string segmentValue = VAR[i].GetER7(options);
				if (string.IsNullOrEmpty(segmentValue) == false) {
					segmentData.Add(segmentValue);
				}
			}
		 }
		 if (ROLE_GOAL != null && ROLE_GOAL.Length > 0) {
			for (int i = 0; i < ROLE_GOAL.Length; i++) {
				string segmentValue = ROLE_GOAL[i].GetER7(options);
				if (string.IsNullOrEmpty(segmentValue) == false) {
					segmentData.Add(segmentValue);
				}
			}
		 }
		 if (OBX != null && OBX.Length > 0) {
			for (int i = 0; i < OBX.Length; i++) {
				string segmentValue = OBX[i].GetER7(options);
				if (string.IsNullOrEmpty(segmentValue) == false) {
					segmentData.Add(segmentValue);
				}
			}
		 }
           return string.Join(HL7ParserConstants.SEGMENT_SEPARATOR, segmentData.ToArray());
        
        }
    }
}

